package com.w.picture;

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration;
import org.jasypt.encryption.StringEncryptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@EnableEncryptableProperties // Jasypt加密 让 Spring Boot 在解析配置文件时自动识别并解密带有 指定前缀的值
//@SpringBootApplication
// 暂时关闭 分库分表 配置,目前代码中的分库分表,如果是公共图库的图片,由于没有空间ID的数据,会导致 分库分表失败
// Insert statement does not support sharding table routing to multiple data nodes.
// 暂时没有改造这部分的代码,所以先关闭分库分表..
@SpringBootApplication(exclude = {ShardingSphereAutoConfiguration.class})
@MapperScan("com.w.picture.mapper")
@EnableAspectJAutoProxy(exposeProxy = true) //exposeProxy=true 可以使用 AopContext
public class WPictureApplication {

    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(WPictureApplication.class, args);

        // 获取加密解密工具类
//        Environment environment = applicationContext.getBean(Environment.class);
//        StringEncryptor encryptor = applicationContext.getBean(StringEncryptor.class);
//
//        // 首先获取配置文件里的原始明文信息
//        String oldPassword = environment.getProperty("cos.client.secretKey");
//
//        // 加密
//        String encryptPassword = encryptor.encrypt(oldPassword);
//        // 解密
//        String decrypt = encryptor.decrypt(encryptPassword);
//
//        // 打印加密前后的结果对比
//        System.out.println("明文密码：" + oldPassword);
//        System.out.println("====================================");
//        System.out.println("加密结果：" + encryptPassword);
//        System.out.println("====================================");
//        System.out.println("解密结果：" + decrypt);
    }

}
